//
//  LGInspectExceptionContentCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/6/13.
//  检查异常项--内容

#import "LGInspectExceptionContentCell.h"

#define nameWidth     (isPad ? viewPix(280) : viewPix(110))

#define resultWidth   (isPad ? viewPix(120) : viewPix(60))

#define itemWidth     (Screen_W-viewPix(66)-nameWidth-resultWidth)/2.0

@interface LGInspectExceptionContentCell() 

/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UIImageView *topView;
/**   */
@property (nonatomic , strong)UIImageView *middleView;
/**   */
@property (nonatomic , strong)UIImageView *bottomView;
/**   */
@property (nonatomic , strong)UILabel *nameLabel;
/**   */
@property (nonatomic , strong)UILabel *resultLabel;
/**   */
@property (nonatomic , strong)UILabel *arrowLabel;
/**   */
@property (nonatomic , strong)UILabel *unitLabel;
/**   */
@property (nonatomic , strong)UILabel *rangeLabel;

@end

@implementation LGInspectExceptionContentCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return  self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    self.cornerType = LGNSString(dataDic[@"contentType"]);
    self.nameLabel.text = LGNSString(dataDic[@"entry_name"]);
    self.resultLabel.text = LGNSString(dataDic[@"result"]);
    self.arrowLabel.text = LGNSString(dataDic[@"arrow"]);
    self.rangeLabel.text = LGNSString(dataDic[@"range"]);
    self.unitLabel.text = LGNSString(dataDic[@"unit"]);
    NSString *colorString = [LGNSString(dataDic[@"arrow_status"]) isEqualToString:@"up"]?@"#DB453A":@"#3291FF";
    self.resultLabel.textColor = [UIColor colorWithString:colorString];
    self.arrowLabel.textColor = [UIColor colorWithString:colorString];
    CGFloat width = [LGNSString(dataDic[@"result"]) textWidthWithFont:LGFontWeight(13, UIFontWeightMedium) maxHeight:MAXFLOAT];
    [self.arrowLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.resultLabel.mas_centerX).offset(width/2.0+3);
    }];
}


-(void)setCornerType:(NSString *)cornerType{
    _cornerType = cornerType;
    
    if([cornerType isEqualToString:@"top"]){
        //上
        [self.topView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.equalTo(@(viewPix(15)));
        }];
        [self.bottomView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.equalTo(@(0));
        }];
        [self.nameLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.bottomView).offset(-viewPix(2));
        }];
        
    }else if ([cornerType isEqualToString:@"middle"]){
        //中
        [self.topView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.equalTo(@(0));
        }];
        [self.bottomView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.equalTo(@(0));
        }];
        [self.nameLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.bottomView).offset(-viewPix(2));
        }];
    }else if ([cornerType isEqualToString:@"bottom"]){
        //下
        [self.topView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.equalTo(@(0));
        }];
        [self.bottomView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.equalTo(@(viewPix(15)));
        }];
        [self.nameLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.bottomView).offset(-viewPix(10));
        }];
    }else{
        //只有一个
        [self.topView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.equalTo(@(viewPix(15)));
        }];
        [self.bottomView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.equalTo(@(viewPix(15)));
        }];
        [self.nameLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.bottomView).offset(-viewPix(10));
        }];
    }
}

#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    self.clipsToBounds = YES;
    self.contentView.backgroundColor = [UIColor colorWithString:@"#F9F9F9"];
    [self.contentView addSubview:self.baseView];
    [self.contentView addSubview:self.topView];
    [self.contentView addSubview:self.middleView];
    [self.contentView addSubview:self.bottomView];
    [self.contentView addSubview:self.nameLabel];
    [self.contentView addSubview:self.resultLabel];
    [self.contentView addSubview:self.arrowLabel];
    [self.contentView addSubview:self.unitLabel];
    [self.contentView addSubview:self.rangeLabel];

    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.equalTo(self.contentView).offset(viewPix(16));
        make.top.right.equalTo(self.contentView).offset(-viewPix(16));
    }];
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(viewPix(28));
        make.right.equalTo(self.contentView).offset(-viewPix(28));
        make.top.equalTo(self.contentView);
        make.height.equalTo(@(viewPix(15)));
    }];
    
    [self.middleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.topView);
        make.top.equalTo(self.topView.mas_bottom).offset(-1);
        make.bottom.equalTo(self.bottomView.mas_top).offset(1);
    }];
    
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.topView);
        make.bottom.equalTo(self.contentView);
        make.height.equalTo(@(viewPix(15)));
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(viewPix(38));
        make.top.equalTo(self.topView).offset(viewPix(10));
        make.bottom.equalTo(self.bottomView).offset(-viewPix(10));
        make.width.equalTo(@(nameWidth));
    }];
    
    [self.resultLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.mas_right);
        make.centerY.equalTo(self.nameLabel);
        make.width.equalTo(@(resultWidth));
    }];
    
    [self.arrowLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.resultLabel.mas_centerX).offset(0);
        make.centerY.equalTo(self.resultLabel);
    }];
    
    [self.unitLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.resultLabel.mas_right);
        make.top.equalTo(self.resultLabel);
        make.width.equalTo(@(itemWidth-5));
    }];
    
    [self.rangeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.unitLabel.mas_right);
        make.top.equalTo(self.resultLabel);
        make.width.equalTo(@(itemWidth+5));
    }];
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [UIView shadowViewWithColor:@"#B2BDC7" offset:CGSizeMake(0, 2) opacity:0.15 radius:10];
        _baseView.backgroundColor = [UIColor whiteColor];
    }
    return _baseView;
}

-(UIImageView *)topView{
    if(!_topView){
        _topView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"异常项背景上"]];
    }
    return _topView;
}

-(UIImageView *)middleView{
    if(!_middleView){
        _middleView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"异常项背景中"]];
    }
    return _middleView;
}

-(UIImageView *)bottomView{
    if(!_bottomView){
        _bottomView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"异常项背景下"]];
    }
    return _bottomView;
}

-(UILabel *)nameLabel{
    if(!_nameLabel){
        _nameLabel = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(13) textAlignment:NSTextAlignmentLeft lines:0];
    }
    return _nameLabel;
}

-(UILabel *)resultLabel{
    if(!_resultLabel){
        _resultLabel = [UILabel lableWithText:@"结果" colorString:@"#333333" textFont:LGFontWeight(13, UIFontWeightMedium) textAlignment:NSTextAlignmentCenter lines:1];
    }
    return _resultLabel;
}

-(UILabel *)arrowLabel{
    if(!_arrowLabel){
        _arrowLabel = [UILabel lableWithText:@"" colorString:@"#EB5757" textFont:LGFont(13) textAlignment:NSTextAlignmentLeft lines:0];
    }
    return _arrowLabel;
}

-(UILabel *)unitLabel{
    if(!_unitLabel){
        _unitLabel = [UILabel lableWithText:@"单位" colorString:@"#666666" textFont:LGFont(13) textAlignment:NSTextAlignmentCenter lines:2];
    }
    return _unitLabel;
}

-(UILabel *)rangeLabel{
    if(!_rangeLabel){
        _rangeLabel = [UILabel lableWithText:@"参考值" colorString:@"#333333" textFont:LGFontWeight(13, UIFontWeightMedium) textAlignment:NSTextAlignmentCenter lines:2];
    }
    return _rangeLabel;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
